//
//  LaunchViewController.m
//  Movie
//
//  Created by tengyang on 15/7/27.
//  Copyright (c) 2015年 tengyang. All rights reserved.
//

#import "LaunchViewController.h"
#import "common.h"
#import "MainTabBarController.h"

@interface LaunchViewController ()

@end

@implementation LaunchViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self _createLaunchImage];
    _index=0;

}

- (void)_createLaunchImage
{
    _imageArray=[[NSMutableArray alloc]init];
    
    CGFloat width=kWidth/4;
    CGFloat height=kHeight/6;
    for (int i=0; i<24; i++) {
        UIImageView *image=[[UIImageView alloc]init];
        
        image.image=[UIImage imageNamed:[NSString stringWithFormat:@"%d@2x.png",i+1]];
        
        if (i<4) {
            image.frame=CGRectMake(i*width, 0, width, height);
        }
        else if (i<8) {
            image.frame=CGRectMake((i-4)*width, height, width, height);
        }
        else if (i<12) {
            image.frame=CGRectMake((i-8)*width, height*2, width, height);
        }
        else if (i<16) {
            image.frame=CGRectMake((i-12)*width, height*3, width, height);
        }
        else if (i<20) {
            image.frame=CGRectMake((i-16)*width, height*4, width, height);
        }
        else {
            image.frame=CGRectMake((i-20)*width, height*5, width, height);
        }
        image.hidden=YES;
        [_imageArray addObject:image];
        [self.view addSubview:image];
    }
     _timer=[NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:@selector(timerAction) userInfo:nil repeats:YES];
    
}
- (void)timerAction
{
    UIImageView *temp=_imageArray[_index];
    temp.hidden=NO;
    _index++;
    if (_index==24) {
        MainTabBarController *vc=[[MainTabBarController alloc]init];
        self.view.window.rootViewController=vc;
        
        [_timer invalidate];
    }
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
